package com.xuyisen.service;


import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.xuyisen.bean.User;
import com.xuyisen.domain.Criteria;
import com.xuyisen.domain.UserRepository;

/**
 * 用户服务类
 * @author sen
 *
 */
@Service
public class UserService {
	@Autowired
	private UserRepository userRepository;
	//添加
	@Transactional
	public void save(User user){
		userRepository.save(user);
	}
	//根据ID删除
	@Transactional
	public void delete(int id){
		userRepository.delete(id);
	}
	//根据ID查找
	@Transactional
	public User findOne(int id){
	   return userRepository.findOne(id);
	}
	//根据对象删除
	@Transactional
	public void delete(User user){
		userRepository.delete(user);
	}
	//删除一系列的对象
	@Transactional
	public void delete(Iterable<User> users){
		userRepository.delete(users);
	}
	//分页查找
	@Transactional
	public Page<User> findAll(Pageable pageable){
		return userRepository.findAll(pageable);
	
	}
	//判断是否存在
	@Transactional
	public boolean exists(int id){
		return userRepository.exists(id);
	}
	//根据工号进行查找
	@Transactional
	public User findByNum(String num){
		return userRepository.findByNum(num);
	}
	//排序查找
	public Page<User> find(Criteria<User> criteria,Pageable pageable){
		return userRepository.findAll(criteria,pageable);
	}
	
}
